package com.marcnuri.MAndFileBrowser;

import mydebug.MyDebug;

import java.io.File;
import java.util.Comparator;

public class FileComparator implements Comparator<File> {
	public static enum Types {
		NAME, SIZE;
	}

	private Types type;

	public FileComparator() {
		this(Types.NAME);
	}

	public FileComparator(Types type) {
		this.type = type;
	}

	public int compare(File file, File compared) {
		MyDebug.beginMethod("compare:int FileComparator");
		switch (type) {
		case SIZE: {
			int giatritrave = new Long(file.length()).compareTo(new Long(compared.length()));
			MyDebug.endMethod();
			return giatritrave;
		}
		default:
			if (file.isDirectory() && compared.isDirectory()) {
				{
					int giatritrave = file.getName().compareTo(compared.getName());
					MyDebug.endMethod();
					return giatritrave;
				}
			} else if (file.isDirectory() && !compared.isDirectory()) {
				{
					int giatritrave = -1;
					MyDebug.endMethod();
					return giatritrave;
				}
			} else if (!file.isDirectory() && compared.isDirectory()) {
				{
					int giatritrave = 1;
					MyDebug.endMethod();
					return giatritrave;
				}
			} else {
				{
					int giatritrave = file.getName().compareTo(
							compared.getName());
					MyDebug.endMethod();
					return giatritrave;
				}
			}
		}
	}

}
